package com.zmj.dao.impl;

import java.util.List;

import com.zmj.dao.IBaseDao;
import com.zmj.utils.DBUtils;

public class BaseDaoImpl implements IBaseDao{
	@Override
	public boolean add(String sql , Object... params) {
		
		try {
			return DBUtils.executeDML(sql, params) > 0;
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return false;
	}

	@Override
	public boolean del(String sql, Object... params) {
		try {
			return DBUtils.executeDML(sql, params) > 0;
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return false;
	}

	@Override
	public boolean upd(String sql, Object... params) {
		try {
			return DBUtils.executeDML(sql, params) > 0;
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return false;
	}

	@Override
	public <T> List<T> sel(Class cls, String sql, Object... params) {
		
		try {
			return DBUtils.executeDQL(cls, sql, params);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	}

	@Override
	public <T> T selOne(Class cls, String sql, Object... params) {
		try {
			return DBUtils.executeDQLByOne(cls, sql, params);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	//获取总记录数
	public int selCount(String sql){
		try {
			return DBUtils.executeCount(sql);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return 0;
	}

}
